package com.anyou.mall.fin.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.anyou.mall.fin.vo.AllOrderAmountVo;
import com.anyou.mall.fin.vo.OrderAmountVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.anyou.common.annotation.Log;
import com.anyou.common.core.controller.BaseController;
import com.anyou.common.core.domain.ApiResult;
import com.anyou.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.anyou.mall.fin.domain.OrderAmount;
import com.anyou.mall.fin.service.IOrderAmountService;
import com.anyou.common.utils.poi.ExcelUtil;
import com.anyou.common.core.page.TableDataInfo;

/**
 * 订单金额管理Controller
 *
 * @author gaochaohao
 * @date 2022-04-25
 */
@Api(tags = "订单金额管理")
@RestController
@RequestMapping("/fin/orderAmount")
public class OrderAmountController extends BaseController
{
    @Autowired
    private IOrderAmountService orderAmountService;

    /**
     * 查询订单金额管理列表
     */
    @ApiOperation("查询订单金额管理列表")
    @PreAuthorize("@ss.hasPermi('fin:orderAmount:list')")
    @GetMapping("/list")
    public TableDataInfo<List<OrderAmountVo>> list(OrderAmount orderAmount)
    {
        startPage();
        List<OrderAmountVo> list = orderAmountService.selectOrderAmountList(orderAmount);
        return getDataTable(list);
    }

    /**
     * 导出订单金额管理列表
     */
    @ApiOperation("导出订单金额管理列表")
    @PreAuthorize("@ss.hasPermi('fin:orderAmount:export')")
    @Log(title = "订单金额管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrderAmount orderAmount)
    {
        List<OrderAmountVo> list = orderAmountService.selectOrderAmountList(orderAmount);
        ExcelUtil<OrderAmountVo> util = new ExcelUtil<OrderAmountVo>(OrderAmountVo.class);
        util.exportExcel(response, list, "订单金额管理数据");
    }

    /**
     * 获取订单金额管理详细信息
     */
    @ApiOperation("获取订单金额管理详细信息")
    @PreAuthorize("@ss.hasPermi('fin:orderAmount:query')")
    @GetMapping(value = "/{orderAmountId}")
    public ApiResult<OrderAmount> getInfo(@PathVariable("orderAmountId") Long orderAmountId)
    {
        return ApiResult.success(orderAmountService.selectOrderAmountByOrderAmountId(orderAmountId));
    }

    /**
     * 新增订单金额管理
     */
    @ApiOperation("新增订单金额管理")
    @PreAuthorize("@ss.hasPermi('fin:orderAmount:add')")
    @Log(title = "订单金额管理", businessType = BusinessType.INSERT)
    @PostMapping
    public ApiResult add(@RequestBody OrderAmount orderAmount)
    {
        return ApiResult.success(orderAmountService.insertOrderAmount(orderAmount));
    }

    /**
     * 修改订单金额管理
     */
    @ApiOperation("修改订单金额管理")
    @PreAuthorize("@ss.hasPermi('fin:orderAmount:edit')")
    @Log(title = "订单金额管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public ApiResult edit(@RequestBody OrderAmount orderAmount)
    {
        return ApiResult.success(orderAmountService.updateOrderAmount(orderAmount));
    }

    /**
     * 删除订单金额管理
     */
    @ApiOperation("删除订单金额管理")
    @PreAuthorize("@ss.hasPermi('fin:orderAmount:remove')")
    @Log(title = "订单金额管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{orderAmountIds}")
    public ApiResult remove(@PathVariable Long[] orderAmountIds)
    {
        return ApiResult.success(orderAmountService.deleteOrderAmountByOrderAmountIds(orderAmountIds));
    }

    /**
     * 获取订单完成总额
     */
    @ApiOperation("获取订单完成总额")
    @PreAuthorize("@ss.hasPermi('fin:orderAmount:allOrderAmount')")
    @GetMapping("/allOrderAmount")
    public ApiResult<AllOrderAmountVo> allOrderAmount() {
        return orderAmountService.allOrderAmount();
    }
}
